package controllers

import (
    "git.oschina.net/hfwb/tianqi.git/tq/model"
)

type Weather struct {
    base
}

func (this *Weather) GetMinuteHistory() {
    code := this.GetString("code")
    limit, _ := this.GetInt("limit", 10)
    m := model.NewMonitorMinute()
    if list, err := m.GetHistoryByStationCode(code, limit); err != nil {
        this.Response(err)
    } else {
        this.Response(list)
    }
}

func (this *Weather) GetHoursHistory() {
    code := this.GetString("code")
    limit, _ := this.GetInt("limit", 10)
    m := model.NewMonitorHours()
    if list, err := m.GetHistoryByStationCode(code, limit); err != nil {
        this.Response(err)
    } else {
        this.Response(list)
    }
}

func (this *Weather) GetAll()  {
    stationList, err := model.NewStation().GetAll()
    if err != nil {
        this.Response(err)
        return
    }
    m := model.NewMonitorMinute()
    for _, v := range stationList {
        his, _ := m.GetHistoryByStationCode(v.Code, 1)
        if len(his) > 0 {
            v.CurrentMinuteMonitor = his[0]
        }
    }
    this.Response(stationList)
}
